unit SynToggleHighlighterDlg;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, SynEdit, SynEditHighlighter, SynHighlighterDlg;

type
  TToggleHighlighterDlg = class(TForm)
    ListBox1: TListBox;
    Edit1: TEdit;
    Button2: TButton;
    Button3: TButton;
    Label2: TLabel;
    Button1: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure ListBox1DblClick(Sender: TObject);
    procedure ListBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ToggleHighlighterDlg: TToggleHighlighterDlg;

implementation

{$R *.dfm}

procedure TToggleHighlighterDlg.Button1Click(Sender: TObject);
begin
  TCustomHLDlg.Create(self).ShowModal;
end;

procedure TToggleHighlighterDlg.Button2Click(Sender: TObject);
begin
  if ListBox1.ItemIndex >= 0 then
    ModalResult := mrOk;
end;

procedure TToggleHighlighterDlg.Edit1Change(Sender: TObject);
var
  i : integer;
  S : string;
begin
  s := LowerCase(Edit1.Text);
  for i := 0 to ListBox1.Items.Count - 1 do
  begin
    if Pos(s, LowerCase(ListBox1.Items[i])) <> 0 then
    begin
      ListBox1.ItemIndex := i;
      exit;
    end;
  end;
end;

procedure TToggleHighlighterDlg.ListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  s : string;
begin
  with ListBox1.Canvas do
  begin
    s := ListBox1.Items[index];
    if (Index mod 2) = 0 then
      Brush.Color := $00F3F3F3;
    if odSelected in State then
    begin
      Brush.Color := clHighlight;
      Font.Color := clHighlightText;
    end;
    FillRect(Rect);
    OffsetRect(Rect, 2, 0);
    DrawText(Handle, PChar(s), Length(s), Rect, DT_VCENTER);
  end;
end;

procedure TToggleHighlighterDlg.ListBox1DblClick(Sender: TObject);
begin
  button2.Click;
end;

procedure TToggleHighlighterDlg.ListBox1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  case Key of
    VK_UP, VK_DOWN, VK_HOME, VK_END, VK_NEXT, VK_PRIOR : Exit;
  else
    begin
      PostMessage(Edit1.Handle, WM_KEYUP, Ord(Key), 0);
      Key := 0;
    end;
  end;
end;

end.
